package com.beiding.workordersystem.resource.controller;

import com.beiding.workordersystem.common.dao.MPage;
import com.beiding.workordersystem.common.standard.R;
import com.beiding.workordersystem.common.utils.MyBeanUtils;
import com.beiding.workordersystem.resource.entity.Resource;
import com.beiding.workordersystem.resource.service.ResourceService;
import com.beiding.workordersystem.resource.vo.ResourceVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/resource")
public class ResourceController {

    @Autowired
    private ResourceService resourceService;

    //分页获取所有
    @GetMapping("/page")
    R page(MPage page, Resource resource,@RequestParam(defaultValue = "false") Boolean my,@RequestParam(defaultValue = "false") Boolean audit) {
        return R.ok(resourceService.page(page.toIPage(), resource, my, audit));
    }
/*
    @GetMapping("/loadChildren")
    R loadChildren(@RequestParam String mainId) {
        return R.ok(resourceService.loadChildren(mainId));
    }*/

    @GetMapping("/details")
    R details(@RequestParam String id) {
        return R.ok(resourceService.details(id));
    }

    //入库
    @PostMapping("/save")
    R save(@RequestBody @Validated ResourceVo vo) {
        Resource resource = MyBeanUtils.copy(vo, Resource.class);
        resourceService.save(resource);
        return R.ok(resource.getId());
    }

    //出库(批)
    @PostMapping("/remove")
    R remove(@RequestBody String[] ids) {
        resourceService.remove(ids);
        return R.ok();
    }

    //领用
    @PostMapping("/take")
    R take(@RequestBody String[] ids) {
        resourceService.take(ids);
        return R.ok();
    }

    //根据权限测试删除
    @PostMapping("/delete")
    R delete(@RequestBody String[] ids) {
        resourceService.delete(ids);
        return R.ok();
    }

    //通过入库申请
    @PostMapping("/passSave")
    R passSave(@RequestBody String[] ids) {
        resourceService.passSave(ids);
        return R.ok();
    }

    @PostMapping("/refuseSave")
    R refuseSave(@RequestBody String[] ids) {
        resourceService.refuseSave(ids);
        return R.ok();
    }
    @PostMapping("/passTake")
    R passTask(@RequestBody String[] ids) {
        resourceService.passTake(ids);
        return R.ok();
    }

    @PostMapping("/refuseTake")
    R refuseTake(@RequestBody String[] ids) {
        resourceService.refuseTake(ids);
        return R.ok();
    }
    @PostMapping("/passRemove")
    R passRemove(@RequestBody String[] ids) {
        resourceService.passRemove(ids);
        return R.ok();
    }
    @PostMapping("/refuseRemove")
    R refuseRemove(@RequestBody String[] ids) {
        resourceService.refuseRemove(ids);
        return R.ok();
    }
    @PostMapping("/passGiveBack")
    R passGiveBack(@RequestBody String[] ids) {
        resourceService.passGiveBack(ids);
        return R.ok();
    }
    @PostMapping("/refuseGiveBack")
    R refuseGiveBack(@RequestBody String[] ids) {
        resourceService.refuseGiveBack(ids);
        return R.ok();
    }

    @PostMapping("/giveBack")
    R giveBack(@RequestBody String[] ids) {
        resourceService.giveBack(ids);
        return R.ok();
    }


}
